import Vue from 'vue'
import Router from 'vue-router'
// import store from '@/store'
// 引入多个模块的规则
import config from './modules/config'
import logs from './modules/interaction_log.js'
import Manage from './modules/Manage'
import taskCenter from './modules/task_page'
import LocManage from './modules/LocManage.js'
// import InboundManage from './modules/InboundManage'
// import OutBoundManage from './modules/OutBoundManage'
// import CheckManage from './modules/CheckManage'
// 动态路由表 => 动态路由(需要权限才可以访问的) 我们这里准备一个数组存放
export const asyncRoutes = [
  // InboundManage,
  // OutBoundManage,
  // CheckManage,
  LocManage,
  taskCenter,
  logs,
  config,
  Manage
]
Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index.vue'),
    hidden: true
  },
  // 看板
  {
    path: '/',
    component: Layout,
    redirect: '/VisualVue',
    children: [

      {
        path: 'VisualVue',
        name: 'VisualVue',
        component: () => import('@/views/dashboard/VisualVue.vue'),
        meta: { title: 'VisualVue', icon: 'el-icon-data-analysis', affix: true, noCache: false }
      }
    ]
  },
  // 监控动画
  {
    path: '/Dashboard',
    component: Layout,
    redirect: '/Dashboard',
    // alwaysShow: true,
    // meta: {
    //   title: 'SCADA',
    //   icon: 'el-icon-s-operation',
    //   affix: false
    // },
    children: [
      {
        path: 'Dashboard',
        name: 'Dashboard',
        component: () => import('@/views/dashboard/index.vue'),
        meta: { title: 'dashboard', icon: 'el-icon-s-operation', affix: false, noCache: false }
      }

    ]
  },
  {
    path: '/playBack',
    component: () => import('@/views/playBack/index.vue'),
    hidden: true
  },
  {
    path: '/lcd',
    component: () => import('@/views/displayScreen'),
    hidden: true
  },
  // 大数据模板
  // {
  //   path: '/visual',
  //   component: () => import('@/views/visual/index.vue'),
  //   hidden: true
  // },
  // 多屏页面
  // {
  //   path: '/visualTable',
  //   component: () => import('@/views/visual/visualTable.vue'),
  //   hidden: true
  // },
  {
    path: '/404',
    component: () => import('@/views/404.vue'),
    hidden: true
  }
  // 404 page must be placed at the end !!!
  // { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  // 进入每个页面从顶部开始
  scrollBehavior: () => ({ y: 0 }),
  routes: [
    ...constantRoutes
    // ...asyncRoutes
  ]
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
// 重置路由（路由实例还是老的那个 但是路由匹配规则已经被替换）
export function resetRouter() {
  const newRouter = createRouter()// 重置new 路由实例
  router.matcher = newRouter.matcher // 重置路由 只要新路由的新规则
  // 拿着新路由实例的路由匹配对象 替换了老的路由实例匹配规则对象
}

// Router.selfaddRoutes = function(params) {
//   Router.matcher = new Router().matcher
//   Router.addRoutes(params)
// }
export default router
